package com.ss.android.article.share.c;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.frameworks.baselib.network.http.util.TaskInfo;
import com.ss.android.account.c.QZone;
import com.ss.android.article.base.ui.BaseDialog;
import com.ss.android.article.browser.R;
import com.ss.android.article.share.e.b;
import com.ss.android.article.share.ui.RecyclerViewWrapper;
import com.ss.android.article.share.ui.RecyclerViewWrapper.c;
import com.ss.android.article.share.ui.RecyclerViewWrapper.d;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.image.AvatarLoader;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class a extends BaseDialog implements b {
    public final class a$a extends com.ss.android.article.share.ui.RecyclerViewWrapper.b {
        private int a;
        private int b;

        public a$a(int arg1, int arg2) {

            this.a = arg1;
            this.b = arg2;
        }

        public final void a(Rect arg3, View arg4, c arg5) {
            Object v0 = arg4.getTag();
            if ((v0 instanceof com.ss.android.article.share.a.a.a$a)) {
                int v0_1 = ((d) v0).d;
                arg3.left = v0_1 == 0 ? this.b : 0;
                if (v0_1 != arg5.a - 1) {
                    arg3.right = this.a;
                    return;
                }

                arg3.right = this.b;
            }
        }
    }

    private boolean a;
    private boolean b;
    private final View.OnClickListener c;
    private boolean d;
    public RecyclerViewWrapper g;
    public RecyclerViewWrapper h;
    public RecyclerViewWrapper i;
    public com.ss.android.article.share.ui.RecyclerViewWrapper.b j;
    public com.ss.android.article.share.ui.RecyclerViewWrapper.b k;
    public com.ss.android.article.share.ui.RecyclerViewWrapper.b l;
    public View n;
    public View o;
    public TaskInfo mTaskInfo;
    public AvatarLoader mAvatarLoader;
    public List r;
    public List s;
    public Resources mResources;
    public b u;
    public TextView mCancleBtn;
    public int w;
    public com.ss.android.article.share.entity.a x;
    public boolean y;

    public a(Activity arg2) {
        super(arg2, R.style.jv);
        this.a = false;
        this.c = new com.ss.android.article.share.c.b(this);
        this.d = true;
        this.b = QZone.a(((Context) arg2));
        QZone.b(((Context) arg2));
        this.mActivity = arg2;
        this.mResources = this.mActivity.getResources();
    }

    public List<com.ss.android.article.share.entity.a> a(List<com.ss.android.article.share.e.a> arg6) {
        List v0_2;
        if (arg6 == null || (arg6.isEmpty())) {
            v0_2 = null;
        } else {
            ArrayList v1 = new ArrayList();
            Iterator v3 = arg6.iterator();
            while (v3.hasNext()) {
                Object v0 = v3.next();
                int v4 = ((com.ss.android.article.share.e.a) v0).getItemId();
                int v2 = (this.b) || v4 != 3 ? 1 : 0;
                if (v2 == 0) {
                    continue;
                }

                com.ss.android.article.share.entity.a v2_1 = new com.ss.android.article.share.entity.a();
                v2_1.e = v4;
                v2_1.a = ((com.ss.android.article.share.e.a) v0).getIconId();
                v2_1.b = ((com.ss.android.article.share.e.a) v0).getTextId();
                v2_1.f = ((com.ss.android.article.share.e.a) v0).getStatus();
                v2_1.g = ((com.ss.android.article.share.e.a) v0).getExtra();
                v2_1.c = ((com.ss.android.article.share.e.a) v0).getIconUrl();
                ((List) v1).add(v2_1);
            }
            v0_2 = v1;
        }

        return v0_2;
    }

    public void a() {
        int v8 = 8;
        int v7 = 4;
        boolean v1 = false;
        List v4 = this.a(this.r);
        this.a(this.g, v4, false, false);
        List v5 = this.a(this.s);
        RecyclerViewWrapper v6 = this.h;
        boolean v3 = v4 == null || v4.size() <= v7 ? false : true;
        boolean v0 = v4 == null || (v4.isEmpty()) ? true : false;
        this.a(v6, v5, v3, v0);
        List v3_1 = this.a(null);
        v6 = this.i;
        v0 = v4 == null || v4.size() <= v7 || v5 == null || v5.size() <= v7 ? false : true;
        if (v4 == null || (v4.isEmpty()) || v5 == null || (v5.isEmpty())) {
            v1 = true;
        }

        this.a(v6, v3_1, v0, v1);
        if (v4 == null || (v4.isEmpty()) || v5 == null || (v5.isEmpty())) {
            UIUtils.setVisibility(this.n, v8);
        }

        if (v5 == null || (v5.isEmpty()) || v3_1 == null || (v3_1.isEmpty())) {
            UIUtils.setVisibility(this.o, v8);
        }
    }

    public void a(RecyclerViewWrapper arg7, List arg8, boolean arg9, boolean arg10) {
        int v1;
        int v4 = R.dimen.hj;
        int v3 = R.dimen.share_dialog_padding;
        if (arg7 != null) {
            if (arg8 != null && !arg8.isEmpty()) {
                arg7.setAdapter(new com.ss.android.article.share.a.a(this.mActivity, arg8, ((b) this), this.mAvatarLoader));
                int v0 = arg8.size();
                if (arg10) {
                    v1 = this.mResources.getDimensionPixelOffset(R.dimen.hk);
                    v0 = (this.w - this.mResources.getDimensionPixelOffset(v4) * v0 - (v0 - 1) * v1) / 2;
                } else {
                    v0 = (arg9) || arg8.size() > 4 ? (this.w - this.mResources.getDimensionPixelOffset(R.dimen.hm) - this.mResources.getDimensionPixelOffset(v3) - (this.mResources.getDimensionPixelOffset(v4) << 2)) / 4 : (this.w - (this.mResources.getDimensionPixelOffset(v3) << 1) - (this.mResources.getDimensionPixelOffset(v4) << 2)) / 3;
                    v1 = v0;
                    v0 = this.mResources.getDimensionPixelOffset(v3);
                }

                if (v1 <= 0) {
                    return;
                }

                if (v0 < 0) {
                    return;
                }

                a$a v2 = new a$a(v1, v0);
                if (arg7 == this.g) {
                    if (this.j != null) {
                        this.g.a(this.j);
                    }

                    this.j = ((com.ss.android.article.share.ui.RecyclerViewWrapper.b) v2);
                } else {
                    if (arg7 == this.h) {
                        if (this.k != null) {
                            this.h.a(this.k);
                        }

                        this.k = ((com.ss.android.article.share.ui.RecyclerViewWrapper.b) v2);
                    } else if (arg7 != this.i) {
                    } else {
                        if (this.l != null) {
                            this.i.a(this.l);
                        }
                        this.l = ((com.ss.android.article.share.ui.RecyclerViewWrapper.b) v2);
                    }
                }

                arg7.b(((com.ss.android.article.share.ui.RecyclerViewWrapper.b) v2));
                return;
            }

            UIUtils.setVisibility(((View) arg7), 8);
        }
    }

    public void a(String arg3, boolean arg4, String arg5) {
        this.x = new com.ss.android.article.share.entity.a();
        this.x.d = arg3;
        this.x.c = arg5;
        this.x.g = Boolean.valueOf(arg4);
    }

    public boolean a(com.ss.android.article.share.entity.a arg4, View arg5, a arg6) {
        boolean v0;
        if (!this.g() || this.u == null) {
            v0 = false;
        } else {
            v0 = this.u.a(arg4, arg5, this);
            this.a = true;
            if (!this.y) {
                this.dismiss();
            }
        }

        this.y = false;
        return v0;
    }

    public int b() {
        return R.layout.base_action_dialog;
    }

    public void c() {
        if (this.g()) {
            this.dismiss();
        }
    }

    public void dismiss() {
        long v4 = 0;
        String v2 = null;
        if (!this.a && this.mActivity != null && !android.support.design.a.isTextEmpty(v2) && (this.d)) {
            MobClickCombiner.onEvent(this.mActivity, v2, "share_cancel_button", v4, v4, ((JSONObject) null));
        }

        if (this.mAvatarLoader != null) {
            this.mAvatarLoader.onDestroy();
        }

        if (this.mTaskInfo != null) {
            this.mTaskInfo.a = true;
        }

        super.dismiss();
    }

    public void e() {
        this.y = true;
    }

    public void f() {
        com.ss.android.j.b.isNightModeToggled();
    }

    protected void onCreate(Bundle arg8) {
        int v5 = -2;
        super.onCreate(arg8);
        this.setContentView(this.b());
        this.setCanceledOnTouchOutside(true);
        int v0 = this.mResources.getDimensionPixelSize(R.dimen.hi);
        int v1 = this.mResources.getDimensionPixelSize(R.dimen.hg);
        Display display = this.getWindow().getWindowManager().getDefaultDisplay();
        Point point = new Point();
        com.bytedance.common.b.b.a(display, point);
        this.w = point.x;
        Window window = this.getWindow();
        if (point.x <= v0 || point.y <= v1 || !TTUtils.a(this.mActivity, point.x, point.y)) {
            window.setLayout(-1, v5);
            window.setGravity(80);
        } else {
            window.setLayout(v0, v5);
            window.setGravity(17);
            this.w = v0;
        }

        if (window.getAttributes().gravity == 80) {
            window.setWindowAnimations(R.style.jd);
        }

        this.mCancleBtn = this.findViewById(com.ss.android.article.browser.R.id.cancel_btn);
        this.g = this.findViewById(com.ss.android.article.browser.R.id.recycler_view);
        this.h = this.findViewById(com.ss.android.article.browser.R.id.recycler_view2);
        this.i = this.findViewById(com.ss.android.article.browser.R.id.recycler_view3);
        this.n = this.findViewById(com.ss.android.article.browser.R.id.content_divider);
        this.o = this.findViewById(com.ss.android.article.browser.R.id.content_divider2);
        this.findViewById(com.ss.android.article.browser.R.id.divider);
        this.mCancleBtn.setOnClickListener(this.c);
        this.mTaskInfo = new TaskInfo();
        int v4 = this.mResources.getDimensionPixelSize(R.dimen.hj);
        this.mAvatarLoader = new AvatarLoader(
                com.ss.android.article.browser.R.drawable.m4,
                this.mTaskInfo,
                new com.ss.android.article.share.f.a(this.mActivity.getApplicationContext()),
                v4,
                new com.ss.android.article.share.c.c(v4, v4));
        this.a();
        this.f();
    }
}

